<template>
  <div class="dialog">
    <el-dialog
      title="修改任务"
      :visible.sync="showDialog"
      width="35%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        :rules="rules"
        class="el-form"
      >
        <el-form-item label="保养结果：" class="w100p" prop="checkResult">
          <el-input
            v-model="formData.checkResult"
            clearable
            placeholder="请输入保养结果"
          />
        </el-form-item>
        <el-form-item label="完成状态：" class="w100p" prop="judgeResult">
          <el-input
            v-model="formData.judgeResult"
            clearable
            placeholder="请输入完成状态"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import maintenanceTaskApi from "@/api/equip-maintenance-manage/maintenance-task";
export default {
  name: '',
  components: { },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      formData: {},
      rules: {
        checkResult: [
          { required: true, message: "请输入保养结果", trigger: ["change", "blur"] }
        ],
        judgeResult: [
          { required: true, message: "请输入完成状态", trigger: ["change", "blur"] }
        ]
      },
      showDialog: this.show
    };
  },

  watch: {
    show(v) {
      this.showDialog = v;
      if (v) {
        this.formData = this.editObject
      }
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    save(formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          maintenanceTaskApi.editDaily(this.formData).then(res => {
            if (res.code === 1) {
              this.$message.success("修改成功！");
              this.close()
            } else {
              this.$message.error(res.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
    close() {
      this.$emit("closeDialog");
    },
    cancel() {
      this.$emit("cancelDialog");
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
